package com.aaa.service.jl.impl;

import com.aaa.dao.sys.MenuDao;
import com.aaa.pojo.Menu;
import com.aaa.service.jl.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuDao menuDao;
    @Override
    public Map<String, List<Menu>> findAll(String username) {
        List<Menu> menuList = menuDao.findAll1(username);
        List<Menu> menuListlevel1 = new ArrayList<>();
        List<Menu> menuListlevel2 = new ArrayList<>();
        Iterator<Menu> iterator = menuList.iterator();
          while (iterator.hasNext()){
              Menu menu = iterator.next();

                if (menu.getMenuType().equals("M")){
                    menuListlevel1.add(menu);
                }
                if (menu.getMenuType().equals("C")){
                    menuListlevel2.add(menu);

                }
        }
        Map<String, List<Menu>> map = new HashMap<>();
        map.put("menuListlevel1",menuListlevel1);
        map.put("menuListlevel2",menuListlevel2);
         return map;
    }

    @Override
    public List<Menu> queryAllMenu() {
        return menuDao.queryAllMenu();
    }

    @Override
    public int count() {
        return menuDao.count();
    }

    @Override
    public int insert(Menu menu) {
        return menuDao.insert(menu);
    }

    @Override
    public Menu findParentNameId(Integer id) {
        return menuDao.findParentNameId(id);
    }

    @Override
    public int update(Menu menu) {
        return menuDao.update(menu);
    }

    @Override
    public int deleteById(String id) {
        return menuDao.deleteById(Integer.parseInt(id));
    }
}
